$(function(){
	getdata.init();
	myLoadUp.loadUpFnContainer();
});
var pagenow = 1;
var m_id = [];
//数据交互
var getdata = {
	init : function(){
		getdata.showMovies();
		// getdata.loadMore();
	},
	//显示所有电影接口
	showMovies : function(){
		var showMoviesUrl = '/movie/getpageMovie.do';
		var param = {
			pagenow : pagenow
		}
		var liTpl;
		publicDom.post(showMoviesUrl,param,function(response){
			response = JSON.parse(response);
			if(response.code == 200){
					console.log(response);
					for(var i = 0; i < response.object.length; i ++){
						liTpl = '<li class="list">'
									+'<div class="list_item">'
										+'<div class="p">'
											+'<img class="p-pic" src='+response.object[i].imgurl+'>'
										+'</div>'
										+'<div class="d">'
											+'<div class="flexRow">'
												+'<span class="movieName">'+response.object[i].m_name+'</span>'
												+'<span class="movieIndex score">'+response.object[i].rate+'<small>分</small></span>'
											+'</div>'
											+'<p class="type">类型:'+response.object[i].type+'</p>'
											+'<p class="actor">主演:'+response.object[i].actor+'</p>'
										+'</div>'
									+'</div>'
								+'</li>';
						$('#goods_container').append(liTpl);
						m_id.push(response.object[i].m_id);
					}
					getdata.toMovieDetail();
				}else{
					layer.msg(response.message);
				}
		},function(err){
				layer.msg('未知错误!');
			})
	},
	//点击加载更多再次向后台发起请求
	// loadMore : function(){
	// 	$('.loadMore').click(function(){
	// 		pagenow = pagenow + 1;
	// 		getdata.showMovies();
	// 	})
	// }

	//跳转到电影详情页面
	toMovieDetail : function(){
		var num;
		var page = 1;
		var i;
		$('.list').click(function(){
			num = $('.list').index(this);
			console.log(num);
			console.log(m_id[num]);
			i=num;
			while(i>=10){
				page++;
				i = i-10;
			}
			console.log(page);
			window.location = "productDetail.html?"+page+"&"+m_id[num];
			page = 1;
		});
	}
}
//下拉更新
var myLoadUp = {
	loadUpFnContainer:function(){
	    // dropload
	    $('.goods_wrapper').dropload({
	        scrollArea : window,
	        domDown : {
	            domClass   : 'dropload-down',
	            domRefresh : '<div class="dropload-refresh">↑上拉加载更多</div>',
	            domLoad    : '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
	            domNoData  : '<div class="dropload-noData">没有更多数据了</div>'
	        },
	        loadDownFn : function(me){
                // 为了测试，延迟1秒加载
                setTimeout(function(){
                    pagenow = pagenow + 1;
					getdata.showMovies();
                    // 每次数据加载完，必须重置
                    me.resetload();
                },0);
	        }	
	    });
	}
}